from GraphGroup import GraphGroup
from networkx import draw_spring
from rpy2 import robjects
import matplotlib.pyplot as plt
from os import mkdir, path

class GraphGroupDraw(GraphGroup):
    
    def drawGraphs(self, directory):
        if not path.exists(directory):
            mkdir(directory)
        index=0
        for graph in self.graphs:
            draw_spring(graph)
            plt.savefig("%s/%snew.png"%(directory, str(index)))
            index += 1 
            plt.clf() 
            
            
    def drawTiHistogram(self, directory, topologicalIndex):
        if not path.exists(directory):
            mkdir(directory)
        indexName = topologicalIndex.name()
        vector = robjects.FloatVector(self.Tis[indexName]) 
        imageName = "%s/%s.png" % (directory, indexName)
        robjects.r.png(imageName, width = 400 , height = 300)
        robjects.r.hist(vector, main = indexName,xlab="", col="lightblue")
        robjects.r('dev.off()')
        
                